Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Assignment Expression (Walrus) In Conditional #220

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

pixeebot[bot]
Copy link
Contributor

@pixeebot pixeebot bot commented Jan 23, 2024

This codemod updates places where two separate statements involving an assignment and conditional can be replaced with a single Assignment Expression (commonly known as the walrus operator).

Many developers use this operator in new code that they write but don't have the time to find and update every place in existing code. So we do it for you! We believe this leads to more concise and readable code.

The changes from this codemod look like this:

- x = foo()
- if x is not None:
+ if (x := foo()) is not None:
      print(x)

The walrus operator is only supported in Python 3.8 and later.

More reading

Powered by: pixeebot (codemod ID: pixee:python/use-walrus-if)

Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cb87a2b) 96.62% compared to head (88bbd84) 96.60%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #220      +/-   ##
==========================================
- Coverage   96.62%   96.60%   -0.02%     
==========================================
  Files         101      101              
  Lines        4298     4275      -23     
==========================================
- Hits         4153     4130      -23     
  Misses        145      145              
Files Coverage Δ
src/codemodder/cli.py 100.00% <100.00%> (ø)
src/codemodder/codemods/utils.py 91.75% <100.00%> (-0.17%) ⬇️
src/codemodder/codemods/utils_mixin.py 93.60% <100.00%> (-0.09%) ⬇️
...er/dependency_management/base_dependency_writer.py 96.77% <100.00%> (-0.11%) ⬇️
...odemodder/dependency_management/setup_py_writer.py 100.00% <100.00%> (ø)
...odemodder/dependency_management/setupcfg_writer.py 90.00% <100.00%> (-0.33%) ⬇️
src/core_codemods/django_receiver_on_top.py 100.00% <100.00%> (ø)
src/core_codemods/file_resource_leak.py 95.91% <100.00%> (-0.07%) ⬇️
src/core_codemods/flask_json_response_type.py 100.00% <100.00%> (ø)
src/core_codemods/harden_pyyaml.py 97.29% <100.00%> (-0.08%) ⬇️
... and 4 more

@clavedeluna
Copy link
Contributor

Nice! 🚀 fixing pylint and I think we should merge this

@clavedeluna clavedeluna force-pushed the pixeebot/drip-2024-01-23-pixee-python/use-walrus-if branch from 582f7eb to cecf19e Compare January 29, 2024 17:53
@clavedeluna clavedeluna force-pushed the pixeebot/drip-2024-01-23-pixee-python/use-walrus-if branch from cecf19e to 88bbd84 Compare January 30, 2024 11:11
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@clavedeluna clavedeluna added this pull request to the merge queue Jan 30, 2024
Merged via the queue into main with commit 57a730a Jan 30, 2024
14 checks passed
@clavedeluna clavedeluna deleted the pixeebot/drip-2024-01-23-pixee-python/use-walrus-if branch January 30, 2024 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants